package com.elitel.common.businessJdbc.oracle;

import com.elitel.common.businessJdbc.BusinessScriptPreparedStatement;

public class OracleScriptPreparedStatement extends BusinessScriptPreparedStatement{

    @Override
    public String getPrecompileSql(){
        // here is page or not pageable
        StringBuilder sb = new StringBuilder();
        if(isPageable()){
            sb.append("SELECT * FROM (  SELECT a.*, ROWNUM RN  FROM ( ")
                .append(getSqlWithPlaceHolder())
                .append(" ) a  ")
                .append(" ) WHERE RN > ")
                .append(getStartSize())
                .append(" and RN <= ")
                .append(getEndSize());
        }else{
            sb.append("select a.* from ( ")
                .append(getSqlWithPlaceHolder())
                .append(" ) a");
        }

        return sb.toString();
    }


    public long getEndSize(){
        return getPageNumber() * getPageSize();
    }

    public long getStartSize(){
        return (getPageNumber() - 1 ) * getPageSize();
    }


}
